var App = require ('../../base/App');
var {randomUtils, logUtils, clickUtils} = require ('../../utils/index');
var aTreasure = require ('./aTreasure');
var aWatchAd = require ('./aWatchAd');
var aWatchVideo = require ('./aWatchVideo');
var inTask = require ('./inTask');
var common = require ('./common');
var pointMap = require ('./pointMap');
var xiGua = new App ('西瓜视频', {
  interval: 10 * 60,
  maxOpenCount: 60,
});
aWatchAd.setStorage (xiGua.storage);
xiGua.run = function () {
  var span = randomUtils.getRandom (2, 5, 60);
  logUtils.info ('先看视频', span, '秒');
  aWatchVideo.setSpan (span);
  aWatchVideo.flow ();
  if (common.inHome ()) {
    if (randomUtils.possible (10, 100)) {
      sleep (randomUtils.getRandom (2, 15, 1000));
      common.toTask ();
      logUtils.info ('进入任务页面！！！');
      inTask.init ();
      sleep (randomUtils.getRandom (1.5, 2, 1000));
      // aWatchAd.flow ();
      sleep (randomUtils.getRandom (1.5, 2, 1000));
      aTreasure.flow ();
    } else {
      this.openCount--;
      if (randomUtils.possible (50, 100)) {
        clickUtils.clickPointMap (pointMap.首页.放映厅);
        sleep (randomUtils.getRandom (15, 30, 1000));
      } else {
        if (randomUtils.possible (50, 100)) {
          clickUtils.clickPointMap (pointMap.首页.商城);
          sleep (randomUtils.getRandom (15, 30, 1000));
        }
      }
    }
  }
};
xiGua.runTest = function (count) {
  if (count == 0) {
    sleep (randomUtils.getRandom (5, 15, 1000));
    return;
  }
  if (count == 1) {
    sleep (randomUtils.getRandom (5, 15, 1000));
    return;
  }
  if (count == 2) {
    sleep (randomUtils.getRandom (5, 15, 1000));
    return;
  }
};
xiGua.randomInHome = function () {};

module.exports = xiGua;
